package com.edt.ichannel.api.service.impl;

import com.edt.ichannel.api.common.constant.CommonConstant;
import com.edt.ichannel.api.dao.RedPacketOrderResultDao;
import com.edt.ichannel.api.entiy.local.RedPacketOrderResult;
import com.edt.ichannel.api.service.RedPacketOrderResultService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * RedPacketOrderResult服务接口实现类
 * @author sl
 * @date 2018-06-26
 */
@Service
public class RedPacketOrderResultServiceImpl implements RedPacketOrderResultService {

    @Resource
    private RedPacketOrderResultDao redpacketorderresultDao;

    private Logger logger = LogManager.getLogger(RedPacketOrderResultServiceImpl.class);

    @Override
    public void insertList(List<RedPacketOrderResult> redPacketOrderResultList) {
        if (redPacketOrderResultList != null){
            int count = CommonConstant.BRANCH_COUNT;
            int lastIndex = count ;
            for(int index = 0; index < redPacketOrderResultList.size();){
                if(lastIndex > redPacketOrderResultList.size()){
                    lastIndex = redPacketOrderResultList.size();
                    redpacketorderresultDao.insertRedPacketOrderResultList(redPacketOrderResultList.subList(index,lastIndex));
                    break;
                }else{
                    redpacketorderresultDao.insertRedPacketOrderResultList(redPacketOrderResultList.subList(index, lastIndex));
                    index = lastIndex;
                    lastIndex = index + (count);
                }
            }
            logger.info("list  长度："+redPacketOrderResultList.size());
        }else{
            logger.info("list为空");
        }
    }
}